package com.example.demo.Config.EssayTask;

import com.example.demo.Utils.RedisUtils.RedisUtil;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.quartz.JobExecutionContext;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.io.IOException;

/**
 * 定时刷新redis
 */
@Slf4j
public class EssayTask extends QuartzJobBean {
    @Resource
    RedisUtil redisUtil;

    @Override
    protected void executeInternal(@NotNull JobExecutionContext jobExecutionContext) {
        try {
            redisUtil.clear();
            redisUtil.deleteKeysStartingWith("");
            log.info("定时清空redis缓存");
        } catch (IOException e) {
            log.error("出问题了:{}", e.getLocalizedMessage());
        }
    }
}
